package com.sd.activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.sd.activity.r.R;
import com.sd.util.PreferencesManager;

/**
 * 
 * 
 * @author Alex.Lu
 * 
 */
public class GuideActivity extends BaseActivity implements OnClickListener {

	private Button mStart;
	private LinearLayout mGuide1LL;
	private LinearLayout mGuide2LL;
	private LinearLayout mGuide3LL;
	private RelativeLayout mGuide4LL;
	private Bitmap guide1;
	private Bitmap guide2;
	private Bitmap guide3;
	private Bitmap guide4;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_guide);
		mGuide1LL = (LinearLayout)findViewById(R.id.whatsnew_00);
		mGuide2LL = (LinearLayout)findViewById(R.id.whatsnew_01);
		mGuide3LL = (LinearLayout)findViewById(R.id.whatsnew_02);
		mGuide4LL = (RelativeLayout)findViewById(R.id.whatsnew_03);
		
		mStart = (Button)findViewById(R.id.start);
		mStart.setVisibility(View.VISIBLE);
		mStart.setOnClickListener(this);
		
		guide1 = BitmapFactory.decodeResource(this.getResources(), R.drawable.whatsnew_00);
		guide2 = BitmapFactory.decodeResource(this.getResources(), R.drawable.whatsnew_01);
		guide3 = BitmapFactory.decodeResource(this.getResources(), R.drawable.whatsnew_02);
		guide4 = BitmapFactory.decodeResource(this.getResources(), R.drawable.whatsnew_03);
		
		mGuide1LL.setBackgroundDrawable(new BitmapDrawable(guide1));
		mGuide2LL.setBackgroundDrawable(new BitmapDrawable(guide2));
		mGuide3LL.setBackgroundDrawable(new BitmapDrawable(guide3));
		mGuide4LL.setBackgroundDrawable(new BitmapDrawable(guide4));
		
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int v_id = v.getId();
		
		switch (v_id) {
		case R.id.start:
			if(PreferencesManager.getInstance().getISFirst()){
				PreferencesManager.getInstance().setISFirst(false);
				Intent intent = new Intent();
				intent.setClass(this, MainTabActivity.class);
				startActivity(intent);
			}
			finish();
			break;

		default:
			break;
		}
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		
		if(!guide1.isRecycled()){
			guide1.recycle();
		}
		if(!guide2.isRecycled()){
			guide2.recycle();
		}
		if(!guide3.isRecycled()){
			guide3.recycle();
		}
		if(!guide4.isRecycled()){
			guide4.recycle();
		}
		
		super.onDestroy();
	}

	

}